def prime(a):
    f = True
    for z in range(2, int(a ** 0.5)+1):
        if a % z == 0:
            f = False
            break
    return f

g = int(input())
if g < 1000 or g > 9999:
    print(0)
else:
    dgts = str(g)
    mx = 0
    for q in range(len(dgts)):
        for w in range(q+1, len(dgts)+1):
            num = int(dgts[q:w])
            if prime(num):
                mx = max(mx, num)
    print(mx)